//
//  JHHotUserTableViewCell.m
//  Liberty Voice
//
//  Created by dlios on 15-5-18.
//  Copyright (c) 2015年 ClearLove. All rights reserved.
//

#import "JHHotUserTableViewCell.h"


@interface JHHotUserTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic,retain)UICollectionView *HotUserColl;
@property(nonatomic,retain)NSMutableArray *arr;
@end

@implementation JHHotUserTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        /**
         创建
         
         :returns: coll
         */
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(self.contentView.frame.size.width /  3 , self.contentView.frame.size.width /  3 + 40);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
//        layout.minimumLineSpacing = 20;
        layout.sectionInset = UIEdgeInsetsMake(10, 15, 10, 10);
        self.HotUserColl = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height) collectionViewLayout:layout];
        _HotUserColl.backgroundColor = [UIColor whiteColor];
        _HotUserColl.collectionViewLayout = layout;
        _HotUserColl.delegate = self;
        _HotUserColl.dataSource = self;
        [_HotUserColl registerClass:[JHHotUserCollectionViewCell class] forCellWithReuseIdentifier:@"h"];
        [self.contentView addSubview:_HotUserColl];
        
    }return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _HotUserColl.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    
}
- (void)setHotUser:(JHHotUser *)hotUser
{
    if (hotUser != _hotUser) {
        [_hotUser release];
        _hotUser = [hotUser retain];
    }

    self.arr = [NSMutableArray array];
//    NSMutableArray *a = [NSMutableArray array];
//    a = hotUser.HotUserArr;
    NSLog(@"%@", hotUser.list);
    for (NSDictionary *d in hotUser.list) {
        JHHotUserColl *move = [[JHHotUserColl alloc] initWithDic:d];
        [_arr addObject:move];
        NSLog(@"%@",_arr);
    }
    [self.HotUserColl reloadData];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //  重用池
    JHHotUserCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"h" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    cell.hotUserColl = _arr[indexPath.row];
    return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _arr.count;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"点击");
    JHUserViewController *a = [[JHUserViewController alloc] init];
    a.str = [_arr[indexPath.row]uid];
    [self.ablumView.navigationController pushViewController:a animated:YES];
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
